<?php
/**
 * The followings are the available columns in table '{{SpamWords}}':
 * @property integer $id
 * @property string $subject
 * @property string $replace
 * @property integer $isvalid
 */
class Spamwords extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return CActiveRecord the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{spamwords}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('subject', 'required'),
			array('isvalid', 'numerical', 'integerOnly'=>true),
			array('subject, replace', 'length', 'max'=>200),
			array('subject', 'unique'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'subject' => t('keyword'),
			'replace' => t('replace'),
			'isvalid' => t('isvalid'),
		);
	}
	
	public function getIsValidText()
	{
	    return $this->isvalid ? t('isvalid') : t('invalid');
	}
	
	
    public static function getAllValidWords()
	{
	    $cacheId = param('cacheIdSpamWords');
	    param('caching') && $data = app()->cache->get($cacheId);
	    if (!param('caching') || $data == false) {
	        $data = self::model()->findAll('isvalid = ' . STATE_ENABLED);
	        param('caching') && app()->cache->set($cacheId, $data, param('expireSpamWords'));
	    }
	    return $data;
	}
	
	
}